-
Notifications
You must be signed in to change notification settings - Fork 32
Add get-*
prefix to getters
#170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This might be too magical, but one possibility would be to emit bindings that cache returned resource handles for simple This puts a decent amount of burden on bindings implementers, but that seems maybe manageable? |
@badeend Great question! I agree with the rule that getters shouldn't be effectful but I don't think returning an owned handle constitutes an "effect" since theoretically owned handles are just "linear" values. I also like @tschneidereit's idea about
Lastly, |
I've updated the PR with your suggestions:
It is not clear to me yet how the bindings can reliably cache properties without the risk of returning stale information. That being said, this is not a problem we need to solve right now, and I do agree that ideally |
@badeend Thanks, lgtm!
Incidentally, I was just reading what Firefox does for property caching in WebIDL: there is a |
As proposed in the last WASI meeting, this PR prefixes the following property-like methods with
get-
:request.method
request.path-with-query
request.scheme
request.authority
request-options.connect-timeout
request-options.first-byte-timeout
request-options.between-bytes-timeout
response.status-code
I don't foresee any trouble with emitting these as properties in source languages.
However, the interface also contains:
fields.entries
request.options
request.headers
&response.headers
request.body
&response.body
I haven't prefixed these yet. Their names are standalone nouns so my OOP brain wants these to follow the property conventions too. E.g., I'd expect a Java binding generator to produce
getEntries
,getOptions
,getHeaders
&getBody
.But using the property convention/syntax generally comes with the implicit assumption that accessing it is cheap, idempotent and/or side-effect free. That's not the case here. For example, the following snippet would normally be idiomatic JavaScript code:
but actually, this creates two new owned
fields
handles that are never disposed of. And all theentries
are copied over fully twice as well. So this seemingly fine code is actually inefficient & leaking resources.I'm ignoring the existence of the
fields.get
method to get the point across :)Ideas on this are welcome. Concretely I want to know how to proceed:
get-*
anyway and leave it for future selves to figure out?@lukewagner Thoughts?